/*
  学习目标：扩展NavBar组件, 支持固定在头部
*/

import Icon from '@/components/Icon';
import { useHistory } from 'react-router-dom';
import styles from './index.module.scss';
import classNames from 'classnames';

interface INavBarProps {
  right?: React.ReactNode;
  children?: React.ReactNode;
  onBack?: () => void;
  // 1. 扩展fixed属性
  fixed?: boolean;
  // 2. 根据fixed拼接类名
}

export default function NavBar({ right, children, onBack, fixed }: INavBarProps) {
  const history = useHistory();

  return (
    <div className={styles.root}>
      <div className={classNames('main', { fixed })}>
        <div className="left">
          <Icon type="iconfanhui" onClick={onBack || history.goBack} />
        </div>

        <div className="title">{children}</div>
        <div className="right">{right}</div>
      </div>
    </div>
  );
}
